package com.lrz.controller;

import com.lrz.common.Result;
import com.lrz.common.StatusCode;
import com.lrz.service.LikeService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/like")
@CrossOrigin
public class LikeController {

    @Resource
    private LikeService likeService;

    @GetMapping("/articleThumbup/{tid}/{userId}")
    public Result thumbup(@PathVariable String tid, @PathVariable Long userId){
        boolean thumbup = likeService.articleThumbup(tid, userId);
        if (thumbup){
            return new Result(true, StatusCode.OK, "点赞成功");
        }else {
            return new Result(false, StatusCode.ERROR, "点赞失败");
        }
    }

    @GetMapping("/articleDelthumbup/{tid}/{userId}")
    public Result delthumbup(@PathVariable String tid, @PathVariable Long userId){
        boolean thumbup = likeService.articleDelThumbup(tid, userId);
        if (thumbup){
            return new Result(true, StatusCode.OK, "取消点赞成功");
        }else {
            return new Result(false, StatusCode.ERROR, "取消点赞失败");
        }
    }

    @GetMapping("/commentThumbup/{tid}/{userId}")
    public Result thumbup1(@PathVariable String tid, @PathVariable Long userId){
        boolean thumbup = likeService.commentThumbup(tid, userId);
        if (thumbup){
            return new Result(true, StatusCode.OK, "点赞成功");
        }else {
            return new Result(false, StatusCode.ERROR, "点赞失败");
        }
    }

    @GetMapping("/commentDelthumbup/{tid}/{userId}")
    public Result delthumbup1(@PathVariable String tid, @PathVariable Long userId){
        boolean thumbup = likeService.commentDelThumbup(tid, userId);
        if (thumbup){
            return new Result(true, StatusCode.OK, "取消点赞成功");
        }else {
            return new Result(false, StatusCode.ERROR, "取消点赞失败");
        }
    }
}
